<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js"
    type="application/javascript"></script>
</head>

<body>
  <div id="app">
    <!-- 🍑1.通过ref操作DOM元素，绑定监听事件 -->
    <!-- <img :src="staffPhoto" ref="image" /> -->

    <!-- 🍑2.自定义事件绑定监听事件 -->
    <img :src="staffPhoto" @error="onerror" />
  </div>
</body>
<!-- <script>
  new Vue({
    el: '#app',
    data () {
      return {
        // staffPhoto: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'
        staffPhoto: 'https://localhost:8080/undefined.jpeg'
      }
    },
    mounted () {
      this.$refs.image.onload = function () {
        console.log('图片加载成功');
      }
      this.$refs.image.onerror = function () {
        console.log('图片加载失败');
        this.src = 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'
      }
    }
  })
</script> -->

<script>
  new Vue({
    el: '#app',
    data () {
      return {
        // staffPhoto: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'
        staffPhoto: 'https://localhost:8080/undefined.jpeg'
      }
    },
    methods: {
      onerror () {
        console.log('加载失败');
        this.staffPhoto = 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'
        console.log('ok');
      }
    }
  })
</script>

</html>